/****************************************
 * 2018 - 2021 版权所有 CopyRight(c) 快程乐码信息科技有限公司所有, 未经授权，不得复制、转发
 */

package com.yuyan.utils;

import ma.glasnost.orika.MapperFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/*****************
 *
 * @author tanj
 * @date 2020/7/10 10:05
 * @version v1.0
 * @description
 *
 */
@Component
public class OrikaUtils {
    @Autowired
    private MapperFactory mapperFactory;
    public  <T, M, S> Map<M, T> mapasMap(Map<M, S> sourceMap, Class<T> clz) {
        if (sourceMap == null || sourceMap.size() <= 0) return null;
        Map<M, T> targetMap = new HashMap<>();
        for (Map.Entry<M, S> entry : sourceMap.entrySet()) {
            T t = mapperFactory.getMapperFacade().map(entry.getValue(), clz);
            targetMap.put(entry.getKey(), t);
        }
        return targetMap;
    }
}
